package Study0;
import java.util.Arrays;

public class Study07 {
    /*对Arrays工具类的使用*/
//    Arrays.deepToString(二维数组对象)
    public static void main (String[] args) {
        int[][] arr = new int[][] {{1,2,3},
                                   {4,5,6},
                                   {7,8,9},
                                   {10},};
        System.out.println(Arrays.deepToString(arr));
    }


//    Arrays.equals(数组对象1，数组对象2)
    public static void main6 (String[] args) {
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
        int[] arr2 = new int[]{1,2,3,4,5,6,7,8,9,10};
        int[] arr3 = new int[]{0,0,0,0,0,0,0,0,0,0};
        System.out.println("arr:arr2= "+Arrays.equals(arr,arr2));
        System.out.println("arr:arr3= "+Arrays.equals(arr,arr3));
    }


//     Arrays.copyOf(数组对象,指定长度)
    public static void main4 (String[] args) {
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
        int[] ret = Arrays.copyOf(arr,arr.length);
        System.out.println("arr:"+Arrays.toString(arr));
        System.out.println("ret:"+Arrays.toString(ret));

    }



//    Arrays.binarySearch(数组对象,查找元素)
    public static void main3 (String[] args) {
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
        int ret = Arrays.binarySearch(arr,10);
        System.out.println(ret); // 找到返回下标
        System.out.println(Arrays.binarySearch(arr,0)); // 没找到返回 负数
    }


//    Arrays.sort(数组对象)
    public static void main2 (String[] args) {
        int[] arr = new int[]{1,6,3,6,7,2,4,5,9,8,10};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
    }



// Arrays.toString(数组对象)
    public static void main1 (String[] args) {
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
        System.out.println(Arrays.toString(arr));
        String str = Arrays.toString(arr);
        System.out.println(str);
    }
}

